class Watcher {
  /**
   *  addWatcher (vm,watcher,key)
   *
   * this.watchers  -> watch
   * 比较watch的key 和 data的key 是否相等
   *
   */

  constructor() {
    this.watchers = [];
  }

  addWatcher(vm, watcher, key) {
    this._addWatchProp({
      key,
      fn: watcher[key].bind(vm),
    });
    // console.log(this.watchers);
  }

  _addWatchProp(watchProp) {
    this.watchers.push(watchProp);
  }

  invoke(key, newValue, oldValue) {
    console.log(key, "key是什么");
    this.watchers.forEach((item) => {
      if (item.key === key) {
        console.log(item, "asdasd");
        item.fn(newValue, oldValue);
      }
    });
  }
}

export { Watcher };
